<?

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/


$db->query ("
	CREATE TABLE expl_friends (
		user INT(6) NOT NULL,
		friend INT(6) NOT NULL,
		PRIMARY KEY (user, friend)
	) TYPE=MyISAM DEFAULT CHARSET=cp1251
");

$get_users = $db->query ("SELECT user_id, user_friends FROM expl_users");

$i=0;
$c=0;

while (list($id, $friends) = $db->fetch_row ($get_users)) {
	
	$friends = explode (',', $friends);
	
	foreach ($friends as $f) {
		if ($f != '') {
			$db->query ("INSERT INTO expl_friends VALUES ($id, ".trim($f).")");
			++$c;
		}
	}
	
	++$i;
	
}

print 'Обработано '.$i.' пользователей и добавлено '.$c.' дружеских записи!';